﻿using Common;
using Common.Consts;
using Common.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using System.Threading.Tasks;
using WinServiceFileListener.Helpers;

namespace WinServiceFileListener
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        private string serviceName;
        private string[] args;
        public ProjectInstaller()
        {
            //InitializeComponent();

            AddService model = new AddService();

            // ServiceOne 安装程序
            ServiceProcessInstaller processInstaller1 = new ServiceProcessInstaller();
            processInstaller1.Account = ServiceAccount.LocalSystem;
            processInstaller1.Password = null;
            processInstaller1.Username = null;

            ServiceInstaller serviceInstaller1 = new ServiceInstaller();
            serviceInstaller1.StartType = ServiceStartMode.Automatic;

            var sModel = model.serviceList.FirstOrDefault(a => a.ServiceName == ServiceConst.ServiceName);

            if (sModel != null)
            {
                serviceInstaller1.ServiceName = sModel.ServiceName;
                serviceInstaller1.Description = sModel.Description;
            }

            this.Installers.Add(processInstaller1);
            this.Installers.Add(serviceInstaller1);
        }


    }
}
